package com_dk;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Auther:dingkai
 * @date:2021/11/30 0030 下午 7:28
 * @Desc:
 */
@WebServlet(urlPatterns = "/registerServlet")
public class registerServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取用户输入的验证码
        String _img = request.getParameter("ckimg");
        //获取服务器生成的验证码
        HttpSession session = request.getSession();
        String code = (String) session.getAttribute("code");
        //为了保证验证是有效的唯一，把上一个给清了
        session.removeAttribute("code");
        //判断
        if (!_img.equalsIgnoreCase(code)) {
            //提示用户
            request.setAttribute("msg", "验证码不正确！");
            request.getRequestDispatcher("/login.jsp").forward(request, response);
            return;
        }
    }

        protected void doGet (HttpServletRequest request, HttpServletResponse response) throws
        ServletException, IOException {
            this.doPost(request, response);
        }
    }

